<template>
  <el-container>
    <!-- 头部 -->
    <el-header height="100px">
      <el-row type="flex" class="row-bg" justify="space-between">
        <el-col :span="2">
          <div class="grid-content bg-purple">
            <img src="../imger/logo.png" alt="" class="LogoImg" width="130px" />
          </div>
        </el-col>
        <el-col :span="10">
          <div class="grid-content bg-purple-light">
            <h1>欢迎使用户管理系统</h1>
          </div>
        </el-col>
        <el-col :span="2">
          <div class="grid-content">
            <el-dropdown @command="goOut">
              <span class="el-dropdown-link" id="users">{{
                userinfo.username
              }}</span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item>退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </el-col>
      </el-row>
    </el-header>
    <el-container id="content">
      <!-- 侧边栏 -->
      <el-aside width="200px">
        <el-menu
          default-active="2"
          class="el-menu-vertical-demo"
          :unique-opened="true"
          :collapse-transition="true"
          :router="true"
        >
          <el-submenu
            :index="val.path"
            v-for="(val, key) in menusData"
            :key="key"
          >
            <template slot="title">
              <span>{{ val.authName }}</span>
            </template>
            <el-menu-item-group>
              <el-menu-item
                id="fontColor"
                v-for="(val2, key2) in val.children"
                :key="key2"
                :index="val2.path"
                >{{ val2.authName }}</el-menu-item
              >
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 内容 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      userinfo: {},
      menusData: [],
    };
  },
  methods: {
    //退出登录
    goOut() {
      // console.log(this.userinfo);
      localStorage.removeItem("userinfo");
      this.$router.push({ path: "/login" });
    },
  },
  async mounted() {
    //获取本地存储的userinfo   之后赋值给userinfo
    this.userinfo = JSON.parse(localStorage.getItem("userinfo"));
    // console.log( this.userinfo);

    //获取侧边栏信息进行遍历
    var { data } = await this.$req.get("/menus");
    // console.log(data);
    if (data.meta.status == 200) {
      this.menusData = data.data;
      // console.log(this.menusData);
    }
  },
};
</script>

<style>
#fontColor {
  color: rgb(255, 0, 0);
}
#content {
  height: 800px;
}
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}
</style>